using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace PocketApps
{
    public partial class History : Form
    {
PocketLibrary.IBlog selected = null;

        ImageList mediaImages = new ImageList();

        public Bitmap selectedImage
        {
            get
            {
                if (listView1.SelectedIndices.Count > 0)
                    return new Bitmap(listView1.Items[listView1.SelectedIndices[0]].SubItems[1].Text);
                else
                    return null;
            }
        }

            public History(PocketLibrary.IBlog blog)
            {
                InitializeComponent();
                selected = blog;
            }

            public string selectedItem
            {
                get
                {
                    if (listView1.SelectedIndices.Count > 0)
                        return listView1.Items[listView1.SelectedIndices[0]].Text;
                    else
                        return null;
                }
            }

            private void menuItem2_Click(object sender, EventArgs e)
            {
                this.DialogResult = DialogResult.OK;
            }

            private void menuItem1_Click(object sender, EventArgs e)
            {
                this.DialogResult = DialogResult.Cancel;
            }

            private void History_Load(object sender, EventArgs e)
            {
                mediaImages.ImageSize = new Size(64, 64);
                PocketLibrary.Media.MediaHistoryClass mhistory = new PocketLibrary.Media.MediaHistoryClass();
                mhistory.GetMedia(selected);

                listView1.Columns.Add("Name", 120, HorizontalAlignment.Left);

                foreach (string item in mhistory.HistoryItems.Keys)
                {
                    ListViewItem listItem = new ListViewItem();
                    Bitmap bm = new Bitmap(mhistory.HistoryItems[item].Filename);
                    mediaImages.Images.Add(bm);
                    listItem.Text = mhistory.HistoryItems[item].Name;
                    listItem.SubItems.Add(mhistory.HistoryItems[item].Filename);

                    listItem.ImageIndex = mediaImages.Images.Count - 1;
                    listView1.Items.Add(listItem);
                }

                listView1.SmallImageList = mediaImages;
                listView1.LargeImageList = mediaImages;

            }
        }
    }